package benchmarks.benchmarktests;

import java.util.List;

import problems.diningphilosophers.philosophers.AbstractPhilosopher;
import problems.diningphilosophers.philosopherssolution.AbstractDiningPhilosophersSolution;

public class DiningPhilosophersTest extends BenchmarkTest<AbstractDiningPhilosophersSolution> {
	private int nbThreads;

	public DiningPhilosophersTest(AbstractDiningPhilosophersSolution solution, int nbThreads) {
		super(solution);
		this.nbThreads = nbThreads;
	}

	@Override
	public Thread[] InitializeThreads() {
		List<AbstractPhilosopher> diningPhilosophers = solution.getPhilosophers();
		Thread[] initializedThreads = new Thread[nbThreads];
		for(int i = 0; i < nbThreads; i++) {
			final AbstractPhilosopher philosopher = diningPhilosophers.get(i);
			initializedThreads[i] = new Thread() {
				public void run() {
					philosopher.getForks();
					philosopher.putForks();
				}
			};
		}
		
		return initializedThreads;
	}

	@Override
	public void runAdditionalTests() {}
}
